package com.scu.hotelsystem.service;

import com.scu.hotelsystem.dao.RoomCateDao;
import com.scu.hotelsystem.pojo.RoomCate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoomCateServiceImpl implements RoomCateService {
    @Autowired
    private RoomCateDao roomCateDao;

    @Override
    public List<RoomCate> searchRoomCateList(RoomCate search, int index, int limit) {
        List<RoomCate> roomCateList;
        roomCateList = roomCateDao.searchValidRoomCate(search, index, limit);
        return roomCateList;
    }

    @Override
    public int updateRoomCate(RoomCate roomCate) {
        return roomCateDao.updateRoomCate(roomCate);
    }

    @Override
    public int addRoomCate(RoomCate roomCate) {
        return roomCateDao.insertAndUpdateRoomCate(roomCate);
    }

    @Override
    public int deleteRoomCate(int[] idList) throws IllegalArgumentException {
        int n = 0;

        try{
            n = roomCateDao.setRoomCatesInvalidById(idList);
        }catch (DataAccessException e){
            throw new IllegalArgumentException("传入数组不能为空");
        }

        return n;
    }
}
